package com.database.service.impl;


import com.database.character.UserAccount;
import com.database.mapper.UserMapper;
import com.database.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
	
	@Autowired
	private UserMapper userMapper;

	@Override
	public int addUser(UserAccount userAccount) {
		userAccount.setUpdateTime(LocalDateTime.now());
		userAccount.setRegisterTime(LocalDate.now());
		userAccount.setGender(0);
		return userMapper.addUser(userAccount);
	}

	@Override
	public int updateUser(UserAccount userAccount) {
		userAccount.setUpdateTime(LocalDateTime.now());
		return userMapper.updateUser(userAccount);
	}

	@Override
	public int deleteUserByUid(Integer userId) {
		return userMapper.deleteUserByUid(userId);
	}

	@Override
	public List<UserAccount> list() {
		return userMapper.list();
	}

	@Override
	public UserAccount getByUid(Integer userId) {
		return userMapper.getByUid(userId);
	}

	@Override
	public UserAccount getByNickname(String nickname) {
		UserAccount newUser = userMapper.getByNickname(nickname);
		System.out.println(newUser);
		return newUser;
	}
}
